home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 5 / MacMania 5.toast / / Internet software / NewsWatcher / NW Source / Source / newart.c < prev    next >
Text File  |  1997-01-09  |  3KB  |  119 lines

  1. /*----------------------------------------------------------------------------
  2.  
  3.     newart.c
  4.  
  5.     This module handles checking for new articles.
  6.     
  7.     Copyright © 1994-1997, Northwestern University.
  8.  
  9. ----------------------------------------------------------------------------*/
  10.  
  11. #include <string.h>
  12.  
  13. #include "glob.h"
  14. #include "newart.h"
  15. #include "news.h"
  16. #include "mark.h"
  17. #include "newswatcher.h"
  18. #include "status.h"
  19. #include "memutil.h"
  20. #include "dialog.h"
  21. #include "group.h"
  22. #include "biglist.h"
  23.  
  24.  
  25.  
  26. /*----------------------------------------------------------------------------
  27.     DoCheckNewArticles 
  28.     
  29.     Check to see if there are any new articles on the server for all of the 
  30.     groups in a user group list.
  31.  
  32.     Entry:    wind = pointer to user group list window.
  33.     
  34.     Exit:    function result = error code.
  35. ----------------------------------------------------------------------------*/
  36.  
  37. OSErr DoCheckNewArticles(WindowPtr wind)
  38. {
  39.     TWindow **info;
  40.     BigListRef groupList;
  41.     TGroup **groupArray;
  42.     long numGroups, numItems, groupIndex, item;
  43.     TGroup theGroup;
  44.     long numUnread;
  45.     Boolean haveSelectedGroup;
  46.     OSErr err = noErr;
  47.     
  48.     err = DisplayStatusMessageNumber(kStrChecking);
  49.     if (err != noErr) return err;
  50.     
  51.     info = (TWindow**)GetWRefCon(wind);
  52.     groupArray = (**info).groupArray;
  53.     numGroups = (**info).numGroups;
  54.     groupList = (**info).groupList;
  55.     numItems = BigLGetNumItems(groupList);
  56.     
  57.     /* Close all child windows. */
  58.     
  59.     while ((**info).childList != nil) {
  60.         err = DoClose((**(**info).childList).childWindow);
  61.         if (err != noErr) return err;
  62.     }
  63.     
  64.     /* Add [lastMess+1, maxlong] to the end of each group unread list. 
  65.        Mark each group in the list for an article range update. */
  66.     
  67.     for (item = 0; item < numItems; item++) {
  68.         groupIndex = BigLGetData(groupList, item);
  69.         theGroup = (*groupArray)[groupIndex];
  70.         numUnread = theGroup.numUnread;
  71.         err = AppendUnreadRange(theGroup.lastMess+1, kMaxLong, &theGroup);
  72.         if (err != noErr) return err;
  73.         theGroup.numUnread = numUnread;
  74.         theGroup.status = 'x';
  75.         (*groupArray)[groupIndex] = theGroup;
  76.     }
  77.     
  78.     /* Get new group article ranges from server. */
  79.  
  80.     err = GetGroupArrayArticleRanges(groupArray, numGroups);
  81.     
  82.     /* Adjust unread lists and redraw unread article counts. Select the first
  83.        group with unread articles, if any. Note that we must do this even if
  84.        we get an error from the call to GetGroupArrayArticleRanges above,
  85.        because we have mucked with the unread lists in the group array, and
  86.        we must put them back the way they were. */
  87.     
  88.     haveSelectedGroup = false;
  89.     for (item = 0; item < numItems; item++) {
  90.         groupIndex = BigLGetData(groupList, item);
  91.         theGroup = (*groupArray)[groupIndex];
  92.         if (theGroup.status == 'x') {
  93.             AdjustUnreadList(&theGroup);
  94.             (*groupArray)[groupIndex] = theGroup;
  95.             RedrawUnreadCount(wind, item);
  96.             if (haveSelectedGroup || theGroup.numUnread == 0) {
  97.                 BigLSelect(groupList, item, false);
  98.             } else {
  99.                 BigLSelect(groupList, item, true);
  100.                 haveSelectedGroup = true;
  101.             }
  102.         } else {
  103.             DisposeGroupUnreadList(&theGroup);
  104.             theGroup.firstMess = 1;
  105.             theGroup.lastMess = 0;
  106.             (*groupArray)[groupIndex] = theGroup;
  107.             RedrawUnreadCount(wind, item);
  108.             BigLSelect(groupList, item, false);
  109.         }
  110.     }
  111.     if (haveSelectedGroup) BigLScrollItemIntoView(groupList,
  112.         BigLGetFirstSelectedItem(groupList),
  113.         kBigLScrollToTop, kBigLScrollToBottom);
  114.     
  115.     /* Return the error code from the call to GetGroupArrayArticleRanges. */
  116.     
  117.     return err;
  118. }
  119.